//订单和支付 相关请求
import request from "./request";

//获取订单信息
export const getOrderMsg = () =>
  request({ method: "get", url: "order/auth/trade" });

//提交订单
export interface OrderItem {
  [id: string]: any;
  orderId: any;
  skuId: number;
  skuName: string;
  imgUrl: string;
  orderPrice: number;
  skuNum: number;
  hasStock: string;
}

export interface OrderInfo {
  traderNo: string;
  consignee: string;
  consigneeTel: string;
  deliveryAddress: string;
  paymentWay: string;
  orderComment: string;
  orderDetailList: Array<OrderItem>;
}

export const postOrderMsg = (OrderInfo: OrderInfo) =>
  request({
    method: "post",
    url: `/order/auth/submitOrder?tradeNo=${OrderInfo.traderNo}`,
    data: OrderInfo,
  });

//获取订单支付信息
export const getPayMsg = (orderId: string) =>
  request({ method: "get", url: `/payment/weixin/createNative/${orderId}` });

//获取我的订单列表
interface pageMsg {
  page: string; //当前页码
  limit: string; //每页显示数量
}
export const getMyOrderList = (pageMsg: pageMsg) =>
  request({
    method: "get",
    url: `/order/auth/${pageMsg.page}/${pageMsg.limit}`,
  });

//轮询接口 查询支付状态
export const controller = new AbortController(); //取消请求
export const loopPayStatus = (orderId: string) =>
  request({
    method: "get",
    url: `/payment/weixin/queryPayStatus/${orderId}`,
    signal: controller.signal,
  });
